package com.fling.entity;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.fling.Constants;
import com.fling.Locator;

public abstract class Entity implements Constants {

	protected boolean exists;
	protected Sprite sprite;
	protected Vector2 position;
	protected boolean hideSprite;
	protected float direction;
	protected boolean flipX, flipY;

	public Entity(Vector2 pos, String path) {
		position = pos;
		if (path != null) {
			this.sprite = new Sprite(new Texture(Gdx.files.internal(path)));
		} else {
			this.sprite = new Sprite(new Texture(Gdx.files.internal(NULL)));
		}
		exists = true;
		hideSprite = false;
		direction = 0;
		flipY = false;
		flipX = false;
	}

	public abstract void update(float delta);

	public void render(SpriteBatch sb) {
		if (!hideSprite && sprite != null) {
			sb.draw(sprite.getTexture(), position.x, position.y, 0, 0, sprite.getWidth(), sprite.getHeight(), SCALE * Locator.getxSpriteScale(),
					SCALE * Locator.getySpriteScale(), direction, 0, 0, (int) sprite.getWidth(), (int) sprite.getHeight(), false, false);
		}
	}

	public void render(SpriteBatch sb, float alpha) {
		sb.setColor(sb.getColor().r, sb.getColor().g, sb.getColor().b, alpha);
		sb.draw(sprite.getTexture(), position.x, position.y, 0, 0, sprite.getWidth(), sprite.getHeight(), SCALE * Locator.getxSpriteScale(), SCALE
				* Locator.getySpriteScale(), direction, 0, 0, (int) sprite.getWidth(), (int) sprite.getHeight(), false, false);
		sb.setColor(sb.getColor().r, sb.getColor().g, sb.getColor().b, 1.0f);
	}

	public void render(SpriteBatch sb, Sprite sp) {
		/*
		 * if (!hideSprite && sprite != null) { sb.draw(sprite.getTexture(),
		 * position.x, position.y, 0, 0, sprite.getWidth(), sprite.getHeight(),
		 * SCALE * scale, SCALE * scale, direction, 0, 0, (int)
		 * sprite.getWidth(), (int) sprite.getHeight(), false, false); }
		 */
	}

	public void render(SpriteBatch sb, TextureRegion tr) {
		/*
		 * if (!hideSprite && sprite != null) { sb.draw(tr, position.x,
		 * position.y, 0, 0, tr.getRegionWidth(), tr.getRegionHeight(), SCALE *
		 * scale, SCALE * scale, direction); }
		 */
	}

	public void dispose() {
		sprite.getTexture().dispose();
	}

	public void delete() {
		exists = false;
	}

	public void revive() {
		exists = true;
	}

	public boolean isExists() {
		return exists;
	}

	public void setExists(boolean exists) {
		this.exists = exists;
	}

	public Vector2 getPosition() {
		return position;
	}

	public void setPosition(Vector2 position) {
		this.position = position;
	}

	public float getDirection() {
		return direction;
	}

	public void setDirection(float direction) {
		this.direction = direction;
	}

	public Sprite getSprite() {
		return sprite;
	}

	public void setSprite(Sprite sprite) {
		this.sprite = sprite;
	}

	public void hideSprite() {
		hideSprite = true;
	}

	public void unhideSprite() {
		hideSprite = false;
	}

	public void setFlipX(boolean flipX) {
		this.flipX = flipX;
	}

	public void setFlipY(boolean flipY) {
		this.flipY = flipY;
	}

}
